<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>添加</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link href="layui/css/layui.css" rel="stylesheet" type="text/css" />
<script src="layui/layui.js"></script>
<script src="jquery-1.8.2.js"></script>
</head>

<body>

	<!-- 查询表单 -->
	<form class="layui-form" action="">
		<div class="layui-form-item">
			<label class="layui-form-label">输入框</label>
			<div class="layui-input-inline">
				<input type="text" name="allCarNo" id="allCarNo" required lay-verify="required"
					placeholder="请输入卡号" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">单选框</label>
			<div class="layui-input-block">
				<input type="radio" name="type" value="0" title="学生" checked>
				<input type="radio" name="type" value="1" title="教师">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo" onclick="chaxun()">查询</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<!-- 添加学生的弹窗 -->
	<div id="tianjiachuangStu" style="display: none">
		<form class="layui-form" onsubmit="return false" id="allNo"
			lay-filter="tianjiaForm">
			<!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
			<div class="layui-form-item">
				<label class="layui-form-label">卡号</label>
				<div class="layui-input-inline">
					<input type="text" name="stuCardNo" id="stuCardNo" placeholder="请输入"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">学生姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="stuName" id="stuName" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-inline">
					<input type="text" name="stuSex" id="stuSex" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">身份编号</label>
				<div class="layui-input-inline">
					<input type="text" name="stuMembershipId"  id="stuMembershipId" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-inline">
					<input type="text" name="stuStatus" id="stuStatus" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">学号</label>
				<div class="layui-input-inline">
					<input type="text" name="stuNo" id="stuNo" placeholder="请输入"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">系</label>
				<div class="layui-input-inline">
					<input type="text" name="edSystem" id="edSystem" placeholder="请输入"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">专业</label>
				<div class="layui-input-inline">
					<input type="text" name="edMajor" id="edMajor" placeholder="请输入"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">学历</label>
				<div class="layui-input-inline">
					<input type="text" name="education" id="education" placeholder="请输入"
						autocomplete="off" class="layui-input">
				</div>
			</div>		
			<div class="layui-input-inline">
					<label class="layui-form-label">资源:</label>
					<div class="layui-input-inline">
						<select name="reId" lay-filter="aihao" id="reId" >
						<c:forEach items="${list}" var="r">
							<option value="${r.reId}">${r.reName}</option>
						</c:forEach>
						</select>
					</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="tianjiabtn" onclick="addLogStu()" >添加提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>

		</form>
	</div>
	<!-- 添加教师的弹窗 -->
	<div id="tianjiachuangTea" style="display: none">
		<form class="layui-form" onsubmit="return false" 
			lay-filter="tianjiaForm">
			<!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
			<div class="layui-form-item">
				<label class="layui-form-label">卡号</label>
				<div class="layui-input-inline">
					<input type="text" name="teCarNo" id="teCarNo" placeholder="请输入"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="teName" id="teName" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-inline">
					<input type="text" name="teSex" id="teSex" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">状态</label>
				<div class="layui-input-inline">
					<input type="text" name="teStatus" id="teStatus" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">科室</label>
				<div class="layui-input-inline">
					<input type="text" name="deName" id="deName" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">资源:</label>
				<div class="layui-input-inline">
					<select name="reId" lay-filter="aihao" id="reId1">
					<c:forEach items="${list}" var="r">
						<option value="${r.reId}">${r.reName}</option>
					</c:forEach>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="tianjiabtn" onclick="addLogTea()" >添加提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		
			
		</form>
	</div>
	<script>
		function chaxun(allCarNo){	
			var allCarNo=document.getElementById("allCarNo").value;
			console.log(allCarNo);
			if(allCarNo != ""){
			if(($('input:radio[name="type"]:checked').val())==1){
				//出现弹窗
				 $.post("getAllCarNo",{"teCarNo":allCarNo},function(res){
					$("#teCarNo").val(res.teCarNo);
					$("#teName").val(res.teName);
					$("#teSex").val(res.teSex);
					$("#teStatus").val(res.teStatus);
					$("#deName").val(res.deName);
				},"json"); 
				
				layer.open({
					type : 1,
					title : '查询教师',
					shadeClose : true,//是否点击遮罩关闭
					shade : [ 0.8, '#393D49' ],//遮罩
					maxmin : true, //开启最大化最小化按钮
					area : [ '800px', '500px' ],//面积
					offset : 'auto',//垂直水平居中
					content : $('#tianjiachuangTea')
					
					
					
				});
			}else{
				
				
				//出现弹窗
				 $.post("getAllNo",{"allCarNo":allCarNo},function(res){
					$("#stuCardNo").val(res.stuCardNo);
					$("#stuName").val(res.stuName);
					$("#stuSex").val(res.stuSex);
					$("#stuMembershipId").val(res.stuMembershipId);
					$("#stuNo").val(res.stuNo);
					$("#stuStatus").val(res.stuStatus);
					$("#edSystem").val(res.edSystem);
					$("#edMajor").val(res.edMajor);
					$("#education").val(res.education);
				},"json"); 
				layer.open({
					type : 1,
					title : '查询学生',
					shadeClose : true,//是否点击遮罩关闭
					shade : [ 0.8, '#393D49' ],//遮罩
					maxmin : true, //开启最大化最小化按钮
					area : [ '800px', '500px' ],//面积
					offset : 'auto',//垂直水平居中
					content : $('#tianjiachuangStu')
				});
			}
			}else{
				alert("卡号未填写");
			}
		
		}
		
		function addLogStu(){
			var allNo=$("#stuCardNo").val();
			var pid=$("#reId").val();
		 	$.post("addLog",{"allNo":allNo,"pId":pid},function(res){
		 		alert(res.msg);
		 		location.reload();
		 		
		 	},"json")
		} 
		function addLogTea(){
			var allNo=$("#teCarNo").val();
			var pid=$("#reId1").val();
		 	$.post("addLog",{"allNo":allNo,"pId":pid},function(res){
		 		alert(res.msg);
		 		location.reload();
		 		
		 	},"json")
		} 
		
		
		
		
	</script> 
	<script>
		//Demo
		layui.use([ 'form', 'layer', 'table' ], function() {
			var form = layui.form;
			var table = layui.table;
			var layer = layui.layer;
			var $ = layui.$;
			
			//监听提交
			form.on('submit(formDemo)', function(data) {
				//layer.msg(JSON.stringify(data.field));
			var allCarNo=document.getElementById("allCarNo").value;
			console.log(allCarNo);
			if(allCarNo != ""){
			if(($('input:radio[name="type"]:checked').val())==0){
				$.post("getAllCarNo",data.field,function(res){
					if(res.date){
						form.val("tianjiaFormStu",res.data);
							//弹窗
						layer.open({
							type : 1,
							title : '查询教师',
							shadeClose : true,//是否点击遮罩关闭
							shade : [ 0.8, '#393D49' ],//遮罩
							maxmin : true, //开启最大化最小化按钮
							area : [ '800px', '500px' ],//面积
							offset : 'auto',//垂直水平居中
							content : $('#tianjiachuangStu')
						});
					}
				},"json");
			}else{
				$.post("getAllCarNo",data.field,function(res){
					if(res.date){
						form.val("tianjiaFormTea",res.data);
							//弹窗
							layer.open({
								type : 1,
								area : [ '800px', '600px' ],
								shadeClose:true,
								content : $('#tianjiachuangTea')
							});
					}
				},"json");
			}
				}else{
					alert("卡号未填写");
				}
				return false;
			});
		
		});
	</script>
</body>

</html>